//
//  LatinMatrix.c
//  algorithmDemo
//
//  Created by 李文深 on 16/7/13.
//  Copyright © 2016年 30pay. All rights reserved.
//  拉丁方阵问题

#include "LatinMatrix.h"
#include <stdlib.h>
#include <stdio.h>

List initMatrix(int num) {
    
    List head = (List)malloc(sizeof(struct Node));
    List p = head;
    for (int i=1; i <= num; i++) {
        List node = (List)malloc(sizeof(struct Node));
        node->data = i;
        node->next = NULL;
        p->next = node;
        p = p->next;
    }
    
    p->next = head->next;
    
    free(head);
    
    return p->next;
}

void printMatrixOrders(List l, int num) {
    
    int tmp1,tmp2;
    tmp1 = tmp2 = num;
    
    List p = l;
    
    while (tmp1--) {
        tmp2 = num;
        
        while (tmp2--) {
            printf("%d\t",p->data);
            p = p->next;
        }
        printf("\n");
        p = p->next;//每输出一行就向右移动一次 
    }
    
}